﻿@using System.Collections.Generic
@using System.Linq
@using MrCMS.Entities.Resources
@using MrCMS.Helpers
@using MrCMS.Paging
@model MrCMS.Web.Areas.Admin.Models.StringResourceSearchQuery
@{
    var resources = ViewData["results"] as IPagedList<StringResource> ?? PagedList<StringResource>.Empty;
    var languageOptions = ViewData["language-options"] as List<SelectListItem> ?? new List<SelectListItem>();
}

@using (Html.BeginForm("Index", "Resource", FormMethod.Get))
{
    <fieldset>
        <legend>
            @Resource("Admin Resources Title", "Resources")
            <span class="btn-group display-inline pull-right">
                @Html.ActionLink(Resource("Admin Resource Export", "Export All"), "Export", "ResourceUpdate", new { }, new { @class = "btn btn-default" })
                @Html.ActionLink(Resource("Admin Resource Export Filtered", "Export As Filtered"), "Export", "ResourceUpdate", new { Model.Key, Model.Value }, new { @class = "btn btn-default" })

                <input type="submit" class="btn btn-primary" value="@Resource("Search")" />
            </span>
        </legend>

        <div class="row">
            <div class="col-lg-4">
                <div class="form-group">
                    @Html.LabelFor(query => query.Key)
                    @Html.TextBoxFor(query => query.Key, new { @class = "form-control" })
                </div>
            </div>
            <div class="col-lg-4">
                <div class="form-group">
                    @Html.LabelFor(query => query.Value)
                    @Html.TextBoxFor(query => query.Value, new { @class = "form-control" })
                </div>
            </div>
            <div class="col-lg-4">
                <div class="form-group">
                    @Html.LabelFor(query => query.Language)
                    @Html.DropDownListFor(query => query.Language, languageOptions, new { @class = "form-control" })
                </div>
            </div>
        </div>
    </fieldset>
}

@if (!resources.Any())
{
    @Resource("Admin Resources No Resources", "No resources")
        }
else
{
    <table class="table table-striped table-condensed" style="overflow: scroll">
        <thead>
            <tr>
                <th>
                    @Resource("Key")
                </th>
                <th>
                    @Resource("Value")
                </th>
                <th>
                    @Resource("Language")
                </th>
                <th>
                    @Resource("Actions")
                </th>
            </tr>
        </thead>
        <tbody>
            @foreach (var resource in resources)
            {
                <tr>
                    <td>
                        @resource.DisplayKey
                    </td>
                    <td>
                        @resource.Value
                    </td>
                    <td>
                        @resource.DisplayUICulture
                    </td>
                    <td>
                        <div class="btn-group">
                            @Html.ActionLink("Edit", "Edit", "Resource", new { id = resource.Id }, new { @class = "btn btn-xs btn-default", data_toggle = "fb-modal" })
                            @if (resource.IsDefault)
                            {
                                @Html.ActionLink("Add an override", "Add", "Resource", new { resource.Key }, new { @class = "btn btn-success btn-xs", data_toggle = "fb-modal" })
                            }
                            else
                            {
                                @Html.ActionLink("Delete", "Delete", "Resource", new { id = resource.Id }, new { @class = "btn btn-danger btn-xs", data_toggle = "fb-modal" })
                            }

                        </div>
                    </td>
                </tr>
            }
        </tbody>
    </table>
}
@Html.Pager(resources, "Index", i => new { page = i })

<fieldset>
    <legend>
        @Resource("Admin Resources Import Resources","Import Resources")
    </legend>
    @using (Html.BeginForm("Import", "ResourceUpdate", FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
        <div class="input-group">
            <input type="file" name="file" class="form-control" />
            <span class="input-group-btn">
                <button class="btn btn-default">@Resource("Admin Resources Import Button", "Import")</button>
            </span>
        </div>
    }
</fieldset>
